# Maintainer: Christian Rebischke <chris.rebischke@archlinux.org>
# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Lucas Werkmeister <mail@lucaswerkmeister.de>
# Contributor: Dave Reisner <dreisner@archlinux.org>

pkgname=mkosi
pkgver=14
pkgrel=3
pkgdesc="Build Legacy-Free OS Images"
arch=(any)
url="https://github.com/systemd/mkosi"
license=(LGPL2.1)
depends=(arch-install-scripts python python-pexpect qemu-img)
makedepends=(python-build python-installer python-setuptools python-wheel)
checkdepends=(python-pexpect python-pytest)
optdepends=(
  'btrfs-progs: raw_btrfs and subvolume output formats'
  'debian-archive-keyring: build Debian images'
  'debootstrap: build Debian or Ubuntu images'
  'cryptsetup: add dm-verity partitions'
  'dosfstools: build bootable images'
  'gnupg: sign images'
  'qemu: run bootable images using QEMU'
  'sbsigntools: sign EFI binaries for UEFI SecureBoot'
  'squashfs-tools: raw_squashfs output format'
  'tar: tar output format'
  'ubuntu-keyring: build Ubuntu images'
  'xz: compress images with xz'
  'zstd: compress images with zstd'
)
source=(
  $pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz
  $pkgname-14-fix_tests.patch::https://github.com/systemd/mkosi/commit/60289499675661169cd7bfda2faf331663a43c73.patch
)
sha512sums=('33a387bda9bd74415719d9081373936ead331135fc5c17276bace1a999ec1b90e6caea37fb0fd832bc89ca75635f3dbd1ed19af7679a7d8a59c85a36120d737f'
            '2deeca538132944ce94fd774c9ef5af618731580f406cdabdfb5e360b715d4b77efd66b8163bc550133a48f84ac4231f4e7eb489dfa35f4567d36ea86124180d')
b2sums=('04fd81233647bac63a21f6a34972b18aa652d1d8ed07e1618b35372fcc6125ee43fbc80501dbcb81a1aa96b69ee372c9c1b8c61b31c3d6319b5f86f1e2a374ac'
        '409359a7ad7fe3cffcb4f6de95717002137c17081e1eec78ec761421e7f9d9ab6ebecd9e6ef64c9838829176dc1f79da1e86ce22e0702bbfa2c55f14f06299ab')

prepare() {
  # fix issues with tests: https://github.com/systemd/mkosi/commit/60289499675661169cd7bfda2faf331663a43c73
  patch -Np1 -d $pkgname-$pkgver -i ../$pkgname-14-fix_tests.patch
}

build() {
  cd $pkgname-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd $pkgname-$pkgver
  pytest -vv
}

package() {
  cd $pkgname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 {NEWS,README}.md -t "$pkgdir/usr/share/doc/$pkgname/"
}
